﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;

namespace BeniBastanYaratProject.Yonetim
{
    public partial class SaglayiciIslemleri : System.Web.UI.Page
    {
        DBBaglantiDataContext db = new DBBaglantiDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack) return;


        }
        SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString);


        protected void Button1_Click1(object sender, EventArgs e)
        {
            //ekleme

            string firmaAdi = txtSFirmaAdi.Text;
            string firmaAdres = txtSFirmaAdres.Text;
            string firmaYetkili = txtSFirmaYetkli.Text;
            string firmaTel = txtSFirmaTel.Text;
            string firmaTel2 = txtSFirmaTel2.Text;
            string firmaTel3 = txtSFirmaTel3.Text;
            string firmaFax = txtSFirmaFax.Text;
            string firmaEposta = txtSFirmaEposta.Text;
            string firmaNot = txtSFirmaNot.Text;

            SqlCommand cmd = new SqlCommand("insert into Saglayicilar (SaglayiciFirmaAdi,SaglayiciFirmaAdresi,SaglayiciFirmaYetkili,SaglayiciFirmaTelefon01,SaglayiciFirmaTelefon02,SaglayiciFirmaTelefon03,SaglayiciFirmaFax,SaglayiciFirmaEposta,SaglayiciFirmaNot) values (@SaglayiciFirmaAdi,@SaglayiciFirmaAdresi,@SaglayiciFirmaYetkili,@SaglayiciFirmaTelefon01,@SaglayiciFirmaTelefon02,@SaglayiciFirmaTelefon03,@SaglayiciFirmaFax,@SaglayiciFirmaEposta,@SaglayiciFirmaNot)  ", cnn);
            cmd.Parameters.AddWithValue("@SaglayiciFirmaAdi", firmaAdi);
            cmd.Parameters.AddWithValue("@SaglayiciFirmaAdresi", firmaAdres);
            cmd.Parameters.AddWithValue("@SaglayiciFirmaYetkili", firmaYetkili);
            cmd.Parameters.AddWithValue("@SaglayiciFirmaTelefon01", firmaTel);
            cmd.Parameters.AddWithValue("@SaglayiciFirmaTelefon02", firmaTel2);
            cmd.Parameters.AddWithValue("@SaglayiciFirmaTelefon03", firmaTel3);
            cmd.Parameters.AddWithValue("@SaglayiciFirmaFax", firmaFax);
            cmd.Parameters.AddWithValue("@SaglayiciFirmaEposta", firmaEposta);
            cmd.Parameters.AddWithValue("@SaglayiciFirmaNot", firmaNot);
            //UrunOzAdi
            cnn.Open();

            cmd.ExecuteNonQuery();


            cnn.Close();

            Response.Redirect("SaglayiciIslemleri.aspx");
            
        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            
        }

        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {

        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int SaglayiciID = int.Parse(e.Keys["SaglayiciID"].ToString());
            var sorgu = (from x in db.Saglayicilars where x.SaglayiciID == SaglayiciID select x).SingleOrDefault();
            if (sorgu != null)
            {
                db.Saglayicilars.DeleteOnSubmit(sorgu);
                db.SubmitChanges();
                Response.Redirect("SaglayiciIslemleri.aspx");
            }

        }

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {

        }

    }
}